package com.dataease.indicatorqa.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/api/chart")
public class ChartDataController {

    private static final String CHART_DATA_KEY_PREFIX = "chart_data:";

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @GetMapping("/data/{chartDataId}")
    public ResponseEntity<Object> getChartData(@PathVariable("chartDataId") String id) {
        String key = CHART_DATA_KEY_PREFIX + id;
        Object data = redisTemplate.opsForValue().get(key);

        if (data == null) {
            return ResponseEntity.notFound().build();
        }

        return ResponseEntity.ok(data);
    }
}